/*-----------------------------------------------------------------------------
 * stock_update.h - Stock update related data structures and routines
 *
 * March 2010, Forhad Ahmed
 *-----------------------------------------------------------------------------
 */

#ifndef _STOCK_UPDATE_
#define _STOCK_UPDATE_

#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "common/include/stock_common.h"


#define STOCK_SERVER_IP   "98.210.96.243"
#define STOCK_SERVER_PORT  23
#define STOCK_TICKER_LEN   20


#define STOCK_ECONNRESET     (-0xFF)
#define STOCK_EMSGSIZE       (-0xFE)
#define STOCK_EMALFORMED     (-0xFD)

typedef struct stock_data_t {
    uint32_t timestamp;
    uint32_t price;
    uint32_t change;
} stock_data;

typedef struct stock_update_t {
    struct in_addr client;
    char           ticker[STOCK_TICKER_LEN];
    stock_data     data;
} stock_update;

typedef struct stock_update_msg_t {
    unsigned char header[STOCK_HEADER_LEN];
    stock_update  update;
} stock_update_msg;


#define STOCK_UPDATE_MSG_SIZE   (sizeof(stock_update_msg))

void 
stock_update_dump(stock_update *upd);


int 
stock_update_send(int sock, struct sockaddr_in *addr, stock_update *upd);


int 
stock_update_recv(int sock, stock_update *upd);

#endif /* _STOCK_UPDATE_ */

